<template>
	<view :class="[isSingle?'mx-3':'']" class="news-list-wrap-item d-flex  py-2 j-sb" @tap="skipToNewsDetail">
		<view class="d-flex flex-column j-sb mr-2" style="width: 450upx">
			<text class="multi-row-over font-34" style="line-height: 48upx;">{{ item.title }}</text>
			<view style="color: #A3A3A3;" class="d-flex j-sb a-center">
				<view class="font-20 d-flex a-center" style="color: #343A40;">
					<text class="mr-2 over origin" style="white-space: nowrap;">{{item.tags ? item.tags.split(',')[0]:'' }}</text>
					<text class="mr-2 origin" style="white-space: nowrap;">{{ item.releaseDataDes }}</text>
					<view class="font-24" >
					<!-- <view class="font-24" v-if="isRecommend"> -->
						<!-- <text class="iconfont icon-comment1 mr-1" style="font-size: 14px;"></text>
						<text class="origin">{{item.commentCount}}</text> -->	
					</view>
				</view>
				<!-- <image v-if="isRecommend" src="../../static/images/recommend.png" style="width: 50upx;height: 26upx;" mode=""></image> -->
				<!-- <text v-if="isRecommend" class="recommend">推荐</text> -->
			</view>
		</view>
		<view>
			<image class="image-list" :src="item.thumb" mode=""></image>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			item: {
				type: Object,
				default: () => {
					return {};
				}
			},
			isRecommend: {
				type: Boolean,
				default: false
			},
			isSingle: {
				type: Boolean,
				default: false
			}
		},
		methods: {
			skipToNewsDetail() {
				const newsId = this.item.contentId;
				const url = this.item.url;
				const thumb = this.item.thumb;
				const title = this.item.title;
				console.log(url)
				uni.navigateTo({
					url: '/pages/index/news-detail/news-detail?id=' + newsId + "&thumb=" + thumb + "&title=" + title + '&link=' +
						url
				})
				//加入历史记录
				let list = uni.getStorageSync('history')
				list = list ? JSON.parse(list) : [];
				console.log(list)
				let index = list.findIndex(v=>v.contentId === newsId)
				if(list.length >= 50){
					list.pop()
				}
				if(index === -1){
					 list.unshift(this.item);
				     uni.setStorageSync('history',JSON.stringify(list))
				}else{
					for (var i = 0; i < list.length; i++) {
					            if (list[i].contentId === newsId) {
					                list.splice(i, 1); // 如果数据组存在该元素，则把该元素删除
					                break;
					            }
						}
					list.unshift(this.item);
					uni.setStorageSync('history',JSON.stringify(list))
				}
				
				
			}
		}
	};
</script>

<style scoped>
	.image-list {
		width: 240rpx;
		height: 150rpx;
	}

	.news-list-wrap-item {
		 border-bottom: 0.5px solid #f6f5ec;
		/* box-shadow: inset 0px -1px 1px -1px #c8c7cc; */
		height: 160rpx;
	}
	.origin{
		color:#999;
	}
	.over {
		overflow: hidden;
		max-width: 152upx;
		/* border: 1px solid #cdcdcd;
		border-radius: 10upx;
		padding-left: 3px; */
		padding-right: 3px;
		letter-spacing:1px
	}
	.recommend{
		width: 50upx;
		height: 26upx;
		font-size: 12px;
		color: #999999; 
		/* //#005bac */
		line-height: 12px;
	}
</style>
